<?php

namespace App\Http\Controllers;

use App\week1;
use Illuminate\Http\Request;

class Week1Controller extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\week1  $week1
     * @return \Illuminate\Http\Response
     */
    public function show(week1 $week1)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\week1  $week1
     * @return \Illuminate\Http\Response
     */
    public function edit(week1 $week1)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\week1  $week1
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, week1 $week1)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\week1  $week1
     * @return \Illuminate\Http\Response
     */
    public function destroy(week1 $week1)
    {
        //
    }
    // 注册
    public function register(Request $request){
        $data['name']=$request['name'];
        $data['pwd']=$request['pwd'];
        $data['phone']=$request['phone'];
        $data['qq']=$request['qq'];
        if (empty($request['name']) || empty($request['pwd'])
            || empty($request['phone']) ||empty($request['qq'])
        ) {
            return ['code'=>1,'msg'=>'数据不能为空','result'=>null];
        }else {
            $res=week1::insertOne($data);
            if (!$res) {
            return ['code'=>0,'msg'=>'添加失败','result'=>null];
            }
            return ['code'=>2,'msg'=>'添加成功','result'=>$res];
        }

    }
    // 登录
    public function login(Request $request){
        $data['name']=$request['name'];
        $data['pwd']=$request['pwd'];
        if (empty($request['name']) || empty($request['pwd'])){
            return ['code'=>1,'msg'=>'数据不能为空','result'=>null];
        }
        $res=week1::login($data);
        if (!$res) {
            return ['code'=>2,'msg'=>'登录成功','result'=>null];
            
        }
    }

}

